// File Buffer Class
// (c) jimon game studio

#ifndef JEH_CFILEBUFFER
#define JEH_CFILEBUFFER

#include "IFileBuffer.h"

namespace je
{
	namespace core
	{
		//! File Buffer Class
		class CFileBuffer:public je::core::IFileBuffer
		{
		private:
			//! Work file name
			jeStringd FileName;

			//! File pointer
			FILE * File;

			//! File Size
			u32 FileSize;

			//! True if we can read file
			u1 IsCanRead;

			//! True if we can write file
			u1 IsCanWrite;

			//! True if locked
			u1 Locked;

			//! Lock Type
			BufferLockType LockType;

			//! Open File
			void OpenFile();

			//! if true - file opened,or writed
			u1 Ok;
		public:
			//! Constructor
			CFileBuffer(const jeStringd & NewFileName,u1 IsRead,u1 IsWrite);

			//! Destructor
			~CFileBuffer();

			//! Lock Buffer
			void Lock(BufferLockType NewLockType);

			//! UnLock Buffer
			void UnLock();

			//! Return True if locked
			u1 IsLocked();

			//! Read Data
			void Read(void * Pointer,u32 SizeInBytes);

			//! Write Data
			void Write(const void * Pointer,u32 SizeInBytes);

			//! Allocate Buffer for data,size is count of objects
			void Allocate(u32 NewSize);

			//! DeAllocate Buffer
			void DeAllocate();

			//! Set Position
			void SetPosition(u32 NewPosition,u1 Relative = false);

			//! Get Position
			u32 GetPosition();

			//! Get Size in bytes
			u32 GetSize();

			//! Get Size of one object
			u32 GetObjectSize();

			//! Return File Name
			const jeStringd & GetFileName();

			//! Return true if file opened,or writed correctlly
			u1 IsOk();
		};
	}
}

#endif
